package com.lanyou.esb.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;

/**
 * 接口平均响应时间
 * 
 * @author Davey.wu
 */
@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_ESB_BU_IF_AVG_RES_TIMES")
public class IfAvgResTimes {
	/** ID **/
	private String id;
	/** 接口ID **/
	private String ifId;
	/** 平均响应时间 **/
	private float avgResTimes;
	/** 开始时间 **/
	private Date startDate;
	/** 时间间隔 **/
	private int interval;
	/** 时间间隔单位 **/
	private String intervalUnit;
	/** 是否可用 **/
	private String isEnable;
	/** 创建人 **/
	private String creator;
	/** 创建时间 **/
	private Date createDate;
	/** 最后更新人员 **/
	private String modifier;
	/** 最后更新时间 **/
	private String lastUpDate;

	public final static Specification<IfAvgResTimes> EmptySpecification = new Specification<IfAvgResTimes>() {
		@Override
		public Predicate toPredicate(Root<IfAvgResTimes> root,
				CriteriaQuery<?> query, CriteriaBuilder cb) {
			return null;
		}
	};

	public static Specification<IfAvgResTimes> idSpecification(String id) {
		return new Specification<IfAvgResTimes>() {
			@Override
			public Predicate toPredicate(Root<IfAvgResTimes> root,
					CriteriaQuery<?> query, CriteriaBuilder cb) {
				query.where(cb.equal(root.get("id"), id));
				return null;
			}
		};
	}

	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = "IF_FTP_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "IF_ID", length = 36)
	public String getIfId() {
		return ifId;
	}

	public void setIfId(String ifId) {
		this.ifId = ifId;
	}

	@Column(name = "AVG_RES_TIMES")
	public float getAvgResTimes() {
		return avgResTimes;
	}

	public void setAvgResTimes(float avgResTimes) {
		this.avgResTimes = avgResTimes;
	}

	@Column(name = "START_DATE")
	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	@Column(name = "INTERVAL_VAL")
	public int getInterval() {
		return interval;
	}

	@Column(name = "INTERVAL_UNIT")
	public void setInterval(int interval) {
		this.interval = interval;
	}

	public String getIntervalUnit() {
		return intervalUnit;
	}

	public void setIntervalUnit(String intervalUnit) {
		this.intervalUnit = intervalUnit;
	}

	@Column(name = "CREATED_DATE", updatable = false)
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public String getLastUpDate() {
		return lastUpDate;
	}

	public void setLastUpDate(String lastUpDate) {
		this.lastUpDate = lastUpDate;
	}

	@Column(name = "IS_ENABLE", length = 2)
	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	@CreatedBy
	@Column(name = "CREATOR", length = 50, updatable = false)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(name = "MODIFIER", length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

}